<template>
<Transition name="down">
  <div class="xtx-message" :style="style[type]" v-show="visible">
      <i class="iconfont" :class="[style[type].icon]"></i>
      <span>{{message}}</span>
    </div>
</Transition>
</template>

<script>
import { onMounted, ref } from 'vue'
export default {
  name: 'XtxMessage',
  props: {
    type: {
      type: String,
      default: 'warn'
    },
    message: {
      type: String,
      required: true,
      default: ''
    }
  },
  setup () {
    const style = {
      warn: {
        icon: 'icon-warning',
        color: '#e6a23c',
        backgroundColor: 'rgb(253,246,246)',
        borderColor: 'rgb(250,236,216)'
      },
      error: {
        icon: 'icon-shanchu',
        color: '#f56c6c',
        backgroundColor: 'rgb(254,240,240)',
        borderColor: 'rgb(253,226,226)'
      },
      success: {
        icon: 'icon-queren2',
        color: '#67c23a',
        backgroundColor: 'rgb(240,249,235)',
        borderColor: 'rgb(225,243,216)'
      }
    }

    // 控制元素显示隐藏
    const visible = ref(false)
    onMounted(() => {
      visible.value = true
    })
    return { style, visible }
  }
}
</script>

<style scoped lang="less">
.down {
    &-enter {
        &-from {
            transform: translate3d(0,-75px,0);
            opacity: 0;
        }
        &-active {
        transition: all .5s;
    }
        &-to {
            transform: none;
            opacity: 1;
        }
}
}
.xtx-message {
    width: 300px;
    height: 50px;
    background: rgb(253,226,226);
    position: fixed;
    top:20px;
    left: 50%;
    margin-left: -150px;
    // transform: translate3d(-50%,0,0);
    z-index: 9999;
    border-radius: 8px;
    // text-align: center;
    padding-left: 20px;
    line-height: 55px;
    font-size: 16px;
    color: red;
    i {
        position: relative;
        top: 1px;
        margin-right: 5px;
    }
}

</style>
